local changbiao = fk.CreateSkill {

  name = "joyex__changbiao",

  tags = {  },

}



changbiao:addEffect("viewas", {
  name = "joyex__changbiao",
  anim_type = "offensive",
  pattern = "slash",
  prompt = "#joyex__changbiao-active",
  card_filter = function(self, player, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) ~= Player.Equip
  end,
  view_as = function(self, player,cards)
    if #cards < 1 then
      return nil
    end
    local c = Fk:cloneCard("slash")
    c.skillName = changbiao.name
    c:addSubcards(cards)
    return c
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(changbiao.name, Player.HistoryPhase) < 1
  end,
  enabled_at_response = Util.FalseFunc,
  before_use = function(self, player, useData)
    useData.extra_data = useData.extra_data or {}
    useData.extra_data.ol_ex__changbiaoUser = player.id
  end,
})

changbiao:addEffect(fk.EventPhaseEnd, {
  name = "#joyex__changbiao_trigger",
  events = {fk.EventPhaseEnd},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@joyex__changbiao_draw-phase") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, "joyex__changbiao", "drawcard")
    player:drawCards(player:getMark("@joyex__changbiao_draw-phase"), "joyex__changbiao")
  end,
})
changbiao:addEffect(fk.CardUseFinished, {
  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return (data.extra_data or {}).ol_ex__changbiaoUser == player.id and data.damageDealt
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@joyex__changbiao_draw-phase", #data.card.subcards)
  end,
})

changbiao:addEffect("targetmod", {
  name = "#joyex__changbiao_targetmod",
  bypass_distances =  function(self, player, skill, card, to)
    return table.contains(card.skillNames, changbiao.name)
  end,
})

return changbiao